﻿#region Header

/*
Remote views based on linq
By

Pascal Hauser 
Dipl. Ing. in Informatik, Hochschule für Technik Rapperswil, 2006
Master Thesis, Hochschule für Technik Rapperswil, 2008-2010

and

Raphael Gfeller
Dipl. Ing. in Informatik, Hochschule für Technik Rapperswil, 2006
Master Thesis, Hochschule für Technik Rapperswil, 2008-2010

*/

#endregion

#region Usings

#endregion

namespace Sebastof.Services.Interfaces {
	/// <summary>
	/// Interface of the change handler, which allows for insertion and deletion of objects. 
	/// Change to the objects are, of coure, done to the objects directly.
	/// There is a SubmitChanges method, which will commit the changes.
	/// </summary>
	public interface IChangeHandlerService {
		#region Public Methods

		/// <summary>
		/// Register an object within change tracking, so it gets commited on a SubmitChanges call.
		/// </summary>
		/// <param name="obj"></param>
		void InsertOnSubmit(object obj);

		/// <summary>
		/// Mark the object for deletion.
		/// </summary>
		/// <param name="obj"></param>
		void DeleteOnSubmit(object obj);

		bool IsThereaNewVersionAvailableForThisObject(object obj);

		/// <summary>
		/// Reloads the data of an object from the server and refreshs the local object with the new data.
		/// </summary>
		/// <typeparam name="T"></typeparam>
		/// <param name="obj"></param>
		void Refresh<T>(T obj) where T : class;

		/// <summary>
		/// Commit all changes, insertions and deletions to the server, which will commit it to the back-end (if necessary).
		/// </summary>
		void SubmitChanges();

		event _ConflictDetectionHandler ConflictDetectionHandler;

		#endregion
	}

	//TODO: document

	public enum EAction {
		Insert,
		Update,
		ReloadObject,
		CommitChanges
	}

	public delegate void _ConflictDetectionHandler(
		EAction oncurredByDoingAction, object clientVersion, object serverVersion, out object resolvedObject);
}